Determining the direction of motion (the heading) is an old problem that faced travelers, sailors, or anyone seeking to know their position accurately. Sensing the earth magnetic field was used long ago for finding direction using magnetic compasses. The earth's magnetic field can be expressed as a dipole magnet where the magnetic north and south poles lie in an axis that does not coincide with the earth's true north and south poles. The difference between the true north and the magnetic north defines an angle called “declination angle” that should be accounted for when determining heading using magnetometer.
The electronic compass is an electronic device that includes magnetometers (magnetic sensors) that are capable of measuring the Earth's magnetic field. Magnetometers have many applications, such as calculating the heading of a vehicle or a pedestrian relative to the earth's magnetic north. A 2-dimensional (2D) electronic compass senses magnetic field via two orthogonally placed magnetometers by which heading can be calculated when the compass is placed in horizontal plane. A 3-dimensional (3D) electronic compass uses three orthogonally placed magnetometers to measure the magnetic field. Heading can be calculated from a 3D electronic compass if the pitch and roll angles are known. Pitch and roll can be used for levelling the 3D magnetometer readings. Heading can be obtained from the 2 levelled horizontal magnetometer readings as follows:
                    Heading        =                              -            arc                    ⁢                                          ⁢                      tan            ⁡                          (                                                M                  y                                                  M                  x                                            )                                                          (        1        )            where My and Mx represent the two levelled measurements of the earth's magnetic field vector in a coordinate system attached to the compass body while Heading is the angle the device makes with the magnetic north.
Magnetometer readings are usually affected by magnetic fields other than the earth's magnetic field; the effects of these fields are not negligible so they result in an inaccurate heading measurement due to corrupted magnetometer readings. Therefore a calibration procedure should be applied to the electronic compass to correct the effect of these interfering fields.
Some examples of different error sources and their effects on magnetometer are as follows (among others):    (i) Hard iron effect which is considered as a constant offset added to each axis of sensor output. This kind of distortion comes from permanent magnets or magnetized iron or steel placed close to the magnetic sensor. If the hard iron distortion source is attached to the same reference frame of the sensor the offset remains constant for all heading orientations.    (ii) Soft iron distortion which arises from the interaction of earth's magnetic field and any magnetically soft iron material such as nickel or iron. Soft iron distortion distorts the earth's magnetic field lines depending on which direction the field acts relative to the sensor. In most cases hard iron distortion will have a much larger contribution to the total error than soft iron.    (iii) Different sensitivities of magnetometer sensors in different axes are one source of error. For example for a triad of magnetometers, the three orthogonally mounted magnetometers are not identical as they have different sensitivities. Therefore when all three magnetometers are subjected to an identical magnetic field, the observed output from each will not be the same due to scale factor errors.    (iv) Other error sources may be due to different factors such as sensor material, sensor fabrication, and temperature.
The above list represents examples of the sources of errors that affect magnetometer sensors. The effects of error sources appear in corrupted magnetometer readings. Calibration parameters can be calculated to correct these readings where each calibration parameter can correct for the effects of one or more error sources. For example when bias is calculated for a magnetometer reading, the bias can be used to correct the reading from both hard iron effects as well as any offset-type error source, whether because of sensor material, sensor fabrication, or temperature. Another example occurs when scale factor is calculated for a magnetometer reading; in such a case the scale factor can be used to correct the reading from sensitivity effects, part of the soft iron effects, as well as any scale factor-type errors source, whether because of sensor material, sensor fabrication, or temperature.
Different approaches are used for calibrating magnetometers; the main goal of magnetometers calibration is to use magnetometers as a heading source. One of the old and well known methods for calibrating a compass is compass swinging. Compass swinging was used for compass calibration for heading determination in marine and aviation when other absolute navigation information systems (such as GPS) were not available. The procedure involves leveling and rotating the vehicle or the aircraft containing the compass through a series of known headings, like performing compass swinging on a compass rose at an airport, or using a calibrated master compass to align the aircraft during the swing which indicates that another heading source is required for calibration. The main drawbacks of using traditional compass swinging are that the method is limited to use with two-axis systems as it cannot be used to calibrate a 3D compass, and that it requires the user to be instructed to rotate the compass in certain predefined directions. Another approach for compass calibration that does not require an external heading source to perform the calibration is depending on that if the compass is rotated, assuming there is no ferrous interference with the earth's field, the locus made by magnetometer readings in 2D forms a circle, similarly in 3D the locus forms a sphere. In some implementations it is assumed that if a 2D compass is rotated in normal operation conditions (in the presence of ferrous interference) the locus of its readings forms a translated hyperbolic shape in case of 2D for example among others, an ellipse, while in 3D it forms a translated hyperboloid shape for example among others, an ellipsoid. This is due to the effects of perturbation caused by ferrous materials such as biases (hard iron effects) in magnetometer readings, scale factors, soft iron effects, etc. Either geometric or mathematical based methods can be used to best fit the magnetometer measurements to the assumed manifold, for example, an ellipse in case of 2D or to an ellipsoid in case of 3D. The main drawback of this approach is that it requires the device having the magnetometers rotate at least 360 degrees in horizontal plane in case of 2D. In case of 3D, a rotation should cover a significant portion of an ellipsoid (if the ellipsoid is the assumed locus); this requires rotating the device having the magnetometers in all directions. This drawback makes the calibration process slow, or may require the user to move the device in certain movement (for example a figure eight), or rotate the vehicle for one complete loop to cover 360 degrees. In the latter scenarios the user becomes involved in the calibration process which is not efficient in daily life scenarios when the user requires an accurate heading from his portable device, for example smart phone or personal navigator or from his vehicle navigation device without getting involved in a calibration process. One available method used for magnetometer calibration exploits the minimum and maximum values of measurements collected during a full rotation of the leveled sensor in the horizontal plane to estimate the scale factors and biases of the compass. This method shares the same drawback of requiring a full rotation which makes the calibration process slower or involves the user to be instructed to rotate the sensor to cover certain orientations.
Thus there is a need for a method and apparatus capable of mitigating such drawbacks by being able to perform fast magnetometer calibration with little space coverage that neither requires performing full rotation of the device nor involves the user to be instructed to rotate the sensor to cover certain orientations.